package com.example.nonacademic_education.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.nonacademic_education.constant.Constant;
import com.example.nonacademic_education.entity.Department;
import com.example.nonacademic_education.service.impl.DepartmentServiceImpl;
import com.example.nonacademic_education.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author:yanghua
 * @Date:2023/4/18 17:13
 */
@RestController
@RequestMapping("department")
public class DepartmentController {

    @Resource
    private DepartmentServiceImpl departmentService;

    @PostMapping("addOne")
    @SaCheckPermission("department.add")
    public R addOne(@RequestBody Department department){
        return departmentService.addOne(department);
    }
    @DeleteMapping("deleteOne")
    @SaCheckPermission("department.delete")
    public R deleteOne(Long id){
        return departmentService.deleteOne(id);
    }
    @PutMapping("updateOne")
    @SaCheckPermission("department.update")
    public R updateOne(@RequestBody Department department){
        return departmentService.updateOne(department);
    }
    @GetMapping("getList")
    @SaCheckPermission("department.query")
    public R getList(int page,int size,String name){
        return departmentService.getList(page,size,name);
    }
    @GetMapping("getIdAndNameList")
    @SaCheckRole(Constant.NORMAL_ADMIN)
    public R getIdAndNameList(String name){
        return departmentService.getIdAndNameList(name);
    }
}
